package Lesson4;

import java.util.Scanner;

public class Clas5TaskNine {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		System.out.println("Please enter the length of the array");
		int n = sc.nextInt();
		int[][] matrix = new int [n][n];
		
		int a;
		for(int i = 0; i < matrix.length; i++)
		{
			for(int j = 0; j < matrix[i].length; j++)
			{
				a = (int)(Math.random()*10);
				matrix[i][j] = a;
			}
		}
		
		for(int i = 0; i < matrix.length; i++)
		{
			for(int j = 0; j < matrix[i].length; j++)
			{
				System.out.print(matrix[i][j] + " ");
			}
			System.out.println();
		}
		
		int row = 0;
		int col = 0;
		int row1 = 0;
		int col1 = 0;
		
		int sum = 0;
		int sumMax = 0;
		
		for(int i = 0; i < matrix.length-1; i++)
		{
			for(int j = 0; j < matrix[i].length -1; j++)
			{
				sum = matrix[i][j] + matrix [i][j+1] + matrix[i+1][j] + matrix[i+1][j+1];
				
				if(sum > sumMax)
				{
					sumMax = sum;
					row = matrix[i][j];
					row1 = matrix[i][j+1];
					col = matrix[i+1][j];
					col1 = matrix[i+1][j+1];
				}
			}
		}
		System.out.println();
		System.out.println(row+ " "+row1);
		System.out.println(col + " " + col1);
		
		
		System.out.println("The max sum is: " + sumMax);
		
		
		
	}

}
